import 'babel-polyfill'
import Vue from 'vue'
import { sync } from 'vuex-router-sync'
import App from './App'
import router from '@/router'
import store from '@/store'
import '@esign-ui/base/dist/styles/esignui.base.css'
import '@/css/common.styl'
import 'driver.js/dist/driver.min.css'
// import '@/css/wangEditor.min.less'
import service from '@/lib/service'
import { PdfView } from '@esign-ui/base'
import { DrawSignaturePad } from '@esign-ui/mobile'
import { LangHelper } from '@esign-ui/helpers'
import data from '@esign-ui/mobile/package/locale/lang/zh-CN'
import '@/lib/flexible.min.js'

// import Eslocale from '@esign-ui/shared/dist/locale'
// import EsZH from '@esign-ui/shared/dist/locale/lang/zh-CN.js'
import {
  Button,
  Select,
  Checkbox,
  Container,
  Header,
  Aside,
  Main,
  Menu,
  Submenu,
  MenuItem,
  Tooltip,
  Input,
  Table,
  TableColumn,
  Tag,
  Option,
  Pagination,
  MessageBox,
  Dialog,
  Form,
  FormItem,
  Row,
  Col,
  RadioGroup,
  Radio,
  Popover,
  Upload,
  Progress,
  Timeline,
  TimelineItem,
  Message,
  Loading,
  Steps,
  Step,
  OptionGroup,
  Tree,
  Cascader,
  Image,
  DatePicker,
  Link,
  Breadcrumb,
  BreadcrumbItem,
  CheckboxButton,
  CheckboxGroup,
  Drawer,
  Card,
  InfiniteScroll,
  Dropdown,
  DropdownMenu,
  DropdownItem,
} from 'element-ui'
import { t } from '@esign-ui/shared/dist/locale'
LangHelper.locale.use('zh-CN', data)
Vue.prototype.$t = LangHelper.t
Vue.prototype.t = t
Vue.use(PdfView)
Vue.use(DrawSignaturePad)
// const VueAppend = require('vue-append') // v-append插入HTML并执行其中的js语句
// Vue.use(VueAppend)

// import ElTreeSelect from 'el-tree-select';
// vue.use(ElTreeSelect);

Vue.component(Button.name, Button)
Vue.component(Select.name, Select)
Vue.component(Checkbox.name, Checkbox)
Vue.component(Container.name, Container)
Vue.component(Header.name, Header)
Vue.component(Aside.name, Aside)
Vue.component(Main.name, Main)
Vue.component(Menu.name, Menu)
Vue.component(MenuItem.name, MenuItem)
Vue.component(Tooltip.name, Tooltip)
Vue.component(Input.name, Input)
Vue.component(Option.name, Option)
Vue.component(OptionGroup.name, OptionGroup)
Vue.component(Table.name, Table)
Vue.component(TableColumn.name, TableColumn)
Vue.component(Pagination.name, Pagination)
Vue.component(Dialog.name, Dialog)
Vue.component(Form.name, Form)
Vue.component(FormItem.name, FormItem)
Vue.component(Row.name, Row)
Vue.component(Col.name, Col)
Vue.component(RadioGroup.name, RadioGroup)
Vue.component(Radio.name, Radio)
Vue.component(Popover.name, Popover)
Vue.component(Upload.name, Upload)
Vue.component(Progress.name, Progress)
Vue.component(Timeline.name, Timeline)
Vue.component(TimelineItem.name, TimelineItem)
Vue.component(Submenu.name, Submenu)
Vue.component(Step.name, Step)
Vue.component(Steps.name, Steps)
Vue.component(Tree.name, Tree)
Vue.component(Cascader.name, Cascader)
Vue.component(Link.name, Link)
Vue.component(Image.name, Image)
Vue.component(DatePicker.name, DatePicker)
Vue.component(Breadcrumb.name, Breadcrumb)
Vue.component(BreadcrumbItem.name, BreadcrumbItem)
Vue.component(CheckboxButton.name, CheckboxButton)
Vue.component(CheckboxGroup.name, CheckboxGroup)
Vue.component(Tag.name, Tag)
Vue.component(Drawer.name, Drawer)
Vue.component(Card.name, Card)
Vue.component(Dropdown.name, Dropdown)
Vue.component(DropdownMenu.name, DropdownMenu)
Vue.component(DropdownItem.name, DropdownItem)
Vue.use(Loading.directive)
Vue.use(InfiniteScroll)

Vue.prototype.$service = service
Vue.prototype.$msgbox = MessageBox
Vue.prototype.$alert = MessageBox.alert
Vue.prototype.$confirm = MessageBox.confirm
Vue.prototype.$prompt = MessageBox.prompt
Vue.prototype.$message = Message

// eslint-disable-next-line no-extend-native
Date.prototype.format = function() {
  let month: any = this.getMonth() + 1
  let day: any = this.getDate()
  if (month < 10) {
    month = `0${month}`
  }
  if (day < 10) {
    day = `0${day}`
  }

  return `${this.getFullYear()}-${month}-${day}`
}
// eslint-disable-next-line no-extend-native
Date.prototype.fullFormat = function() {
  let month: any = this.getMonth() + 1
  let day: any = this.getDate()
  let hours: any = this.getHours()
  let min: any = this.getMinutes()
  let sec: any = this.getSeconds()
  if (month < 10) {
    month = `0${month}`
  }
  if (day < 10) {
    day = `0${day}`
  }
  if (hours < 10) {
    hours = `0${hours}`
  }
  if (min < 10) {
    min = `0${min}`
  }
  if (sec < 10) {
    sec = `0${sec}`
  }

  return `${this.getFullYear()}-${month}-${day}T${hours}:${min}:${sec}`
}

Vue.prototype.$downloadFile = function(data: string, fileName: string) {
  // byte[]文件下载
  if (!data) {
    return
  }
  const url = window.URL.createObjectURL(new Blob([data]))
  const link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', fileName)
  document.body.appendChild(link)
  link.click()
  link.remove()
}

Vue.prototype.$downloadFileOfUrl = function(url: string, fileName: string) {
  // url文件下载
  if (!url) {
    return
  }
  let iframe = document.getElementById('myIframe') as HTMLIFrameElement
  if (iframe) {
    iframe.src = url
  } else {
    iframe = document.createElement('iframe')
    iframe.style.display = 'none'
    iframe.src = url
    iframe.id = 'myIframe'
    document.body.appendChild(iframe)
  }
}

Vue.config.productionTip = false
sync(store, router)
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
